var express = require("express");
var router = express.Router();
var { sederModel, conModel, courseModel, curriculumModel, orderModel } = require("../model/zw");
router.get("/seder", async (req, res) => {
  let data = await sederModel.find();
  res.send({
    code: 200,
    msg: "列表展示成功",
    data,
  });
});
router.get("/con", async (req, res) => {
  const tid = req.query.tid;
  var data = [];
  if (tid) {
    let arr = await conModel.find().populate("bid");
    arr.forEach((item) => {
      if (item.bid._id == tid) {
        data.push(item)
      }
    })
  } else {
    res.send({
      code: 200,
      msg: "列表展示成功",
      data: [],
    })
  }

  res.send({
    code: 200,
    msg: "列表展示成功",
    data,
  });
});

router.get("/course", async (req, res) => {
  let data = await courseModel.find();
  res.send({
    code: 200,
    msg: "列表展示成功",
    data,
  });
});

router.get("/curriculum", async (req, res) => {
  let data = await curriculumModel.find();
  res.send({
    code: 200,
    msg: "列表展示成功",
    data,
  });
});

router.post("/order", (req, res) => {
  let body = req.body;
  orderModel.create(body.title);
  res.send({
    code: 200,
    msg: "ok",
  });

});
module.exports = router;
